/////////////////////////////////////////////////////////////////////////////
*Appendix Table 1 ROBUSTNESS for Mincer Gender Wage Gaps
/////////////////////////////////////////////////////////////////////////////

est clear

local var logwage

	quietly{
eststo clear

//Load data
use Data\klips_workingdata_hh, clear

//Keep if years 2010-19, age 25-54
keep if years>=2010 & years<=2019
keep if age>=25 & age<=54

//Define cross-sectional weight for multi-year analysis for only those 25-54: reweight to sum to 100 in each year so that no year weights more than another year in a multi-year regression
foreach weightvar in _weight09_ _weight18_{
bysort years: egen temp_tot`weightvar' = total(`weightvar')
gen temp_`weightvar'_new = 100*`weightvar'/temp_tot`weightvar'
}
drop temp_*
gen _weight2554_ = _weight09__new if years>=2009 & years<2018
replace _weight2554_ = _weight18__new if years>=2018

//Specify regression options
local weight [pw=_weight2554_]
local stderrors robust cluster(pid)

local col 
local nocol
local col2
local i 
local j 
local plotvars
local tabvars

//Controls
	global nocontrols i.years i.age  i.residence
	global controls i.years i.age i.edu  i.residence
	global midcontrols  i.years i.age i.edu i.residence i.ind i.occ 
	global fullcontrols  i.years i.age i.edu i.residence i.ind i.occ worktime i.status i.union i.workplace
	
//Options for reressions and figures for different dependent variables
	global depvar `var'
	global cond if !missing(working) & !missing(age) & !missing(edu) & !missing(residence) & !missing(ind) & !missing(occ) & !missing(worktime) & !missing(status) & !missing(union) & !missing(workplace)
	global label log wage
	global title B: $label
	global axes xsc(r(-0.55 0.15 )) xlabel(-0.5 (0.1) 0.1)
	global legend legend(title("{bf: Specification}") pos(6) cols(2) order(2 "Year, age, region" 4 "+ education" 6 "+occ, ind" 8 "+ hours, work status, union, workplace type" 10 "sample restricted: only if not missing workplace size" 12 "+ log workplace size" 14 "+ inferred years of work experience"))


	}

***********************
//Regressions - all ages

	// Display sample size
	noisily{
	di "Sample size: `var'"
	di "Observations"
	count $cond
	}
		preserve
			 keep $cond
			 keep pid 
			 duplicates drop
			 	noisily{
			 di "Unique individuals"
			 count
				}
		restore
	
	//Generate separate female dummy for age group (for ease of axis labeling on coefficient plot)
	lab var female "{bf: All ages}"
	
	//No controls
	qui : reg $depvar female $nocontrols $cond   `weight', `stderrors'
	est sto e_0_all
	
	//Basic controls (age, education, residence)
	qui : reg $depvar female  $controls $cond   `weight', `stderrors'
	est sto e_1_all
	
//Mid-level controls (adding occ, ind)
	qui : reg $depvar female  $midcontrols $cond `weight', `stderrors'
	est sto e_2_all

	//Full controls (occ, ind, workplace, job)
	qui : reg $depvar female  $fullcontrols $cond  `weight', `stderrors'
	est sto e_3_all

	//Full controls, sample restricted only if not missing workplace size
	qui : reg $depvar female  $fullcontrols $cond & !missing(logemployersize) `weight', `stderrors'
	est sto e_4_all
	
	//Full controls, and log workplace size
	qui : reg $depvar female logemployersize $fullcontrols $cond & !missing(logemployersize) `weight', `stderrors'
	est sto e_5_all
	
		//Full controls, and years of work experience
	qui : reg $depvar female i.yearsworking $fullcontrols $cond `weight', `stderrors'
	est sto e_6_all
	


//Estimates
noisily{
di "`var'" 
esttab e_0_all e_1_all e_2_all e_3_all e_6_all e_4_all e_5_all  using Tables\AppendixTable1.rtf , replace se keep(female*)
}

//Coefficient plot
coefplot e_0_all e_1_all e_2_all e_3_all e_4_all e_5_all e_6_all ///
 , keep(female*) $legend  $axes ylabel(, angle(45))  xline(0, lwidth(thin) lcolor(red)) title("$title") xtitle("Gender $label gap" "2010-19, (men=0)") headings(female_25_29 = "{bf: By age}", angle(45)) yline(2, lwidth(thin) lpattern(solid)) yline(2.1, lwidth(thin) lpattern(solid))

	

 